let prices = 0;//价格排序
let type = "默认";//价格排序
layui.use(['form', 'slider'], function () {
    var form = layui.form
        , layer = layui.layer;
    
    form.on('select(setareas)', function (data) {
        var indexGID = data.elem.selectedIndex;
        type = data.elem[indexGID].title;
        gouzaopage()
    });
    
    form.on('select(setprices)', function (data) {
        var indexGID = data.elem.selectedIndex;
        prices = data.elem[indexGID].title;
        if(prices=='2'){
        	Descending();
        }else{
            Ascending();
        }
    });
});
var newslist = new Vue({
    el: '#newslist',
    data() {
        return {
            newslistdata: [],
            help:[],
        }
    },
    mounted: function () {
        this.gouzaopage();
        window.gouzaopage = this.gouzaopage;
        window.Ascending=this.Ascending;
        window.Descending=this.Descending;
    },
    methods: {
        //创建layui的分页
        gouzaopage:function () {
        	var that=this
            $.ajax({
                url: basePath + "/help/getdata",
                data: {
                	type:type,
                },
                contentType: "application/json;charset=UTF-8", //发送数据的格式
                type: "get",
                dataType: "json", //回调
                success: function (res) {
                   that.help=res.data;
                },error:function () {
                    layer.msg("系统错误", {
                        time: 1000,
                        icon: 2,
                        offset: '100px'
                    });
                }
            });
        },//进行升序排序
        Ascending: function() {
			var array=this.$data.help;
			for (var i = 0; i < array.length; i++) {
				for (var j = 0; j < array.length - 1 - i; j++) {
					if (array[j].help_price > array[j + 1].help_price) {
						var temp = array[j];
						array[j] = array[j + 1];
						array[j + 1] = temp;
					}
				}
			}
			this.$data.help=array;
			this.$forceUpdate();
		},//进行降序排序
		Descending: function() {
			var array=this.$data.help;
			for (var i = 0; i < array.length; i++) {
				for (var j = 0; j < array.length - 1 - i; j++) {
					if (array[j].help_price < array[j + 1].help_price) {
						var temp = array[j];
						array[j] = array[j + 1];
						array[j + 1] = temp;
					}
				}
			}
			this.$data.help=array;
			this.$forceUpdate();
		}
    }
})